package com.zb_study.homework2;


public class Homework02 {
    public static void main(String[] args) {
        A a1 = new A();
        Thread thread1 = new Thread(a1);
        thread1.setName("t1");
        Thread thread2 = new Thread(a1);
        thread2.setName("t2");
        thread1.start();
        thread2.start();
    }
}


class A implements Runnable {
    private int count = 10000;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if(count<1000) {
                    System.out.println("余额不变 ");
                    break;
                }

                count -= 1000;
                System.out.println(Thread.currentThread().getName() + "取了1000元 " + "还有" + count + "钱");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}


